package com.zcy.gift.exception;

/**
 * 自定义的业务异常,如果是能够预知的业务异常,我们就抛出这个BusinessException
 *
 * 业务异常的错误信息,我们是要直接返回给用户展示的
 * 系统异常,我们要封装成友好的提示后再返回
 */
public class BusinessException extends RuntimeException{

    // 业务异常的响应码
    private Integer code;

    public BusinessException() {
        super();
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    // 传入一个响应码对象过来,获取响应码对象的code和message分别赋值,然后就可以通过当前异常类的getCode获取到当前业务异常的响应码
    public BusinessException(ResponseCode code) {
        super(code.getMessage());
        this.code = code.getCode();
    }

    protected BusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public Integer getCode() {
        return code;
    }
}
